<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
</head>

<body>
    <form id="registerForm">
        <label for="username">用户名：</label>
        <input type="text" class="username" id="username" name="username" required><br><br>
        <label for="password">密码：</label>
        <input type="password" id="password" name="password" required><br><br>
        <button type="submit">注册</button>
    </form>

    <script>
        const user = document.querySelector('.username').value;
        document.getElementById('registerForm').addEventListener('submit',
            (event) => {
                event.preventDefault(); // 阻止表单默认提交行为
                var username = document.getElementById('username').value;
                var password = document.getElementById('password').value;
                if (username === '' || password === '') {
                    alert('用户名和密码不能为空！');
                } else {
                    alert('注册成功！');
                }
            });
    </script>
</body>

</html>